﻿namespace Rsdn.Janus
{
    using System;
    using System.ComponentModel;
    using Framework;
    using JetBrains.Annotations;
    using SmartApp;

    [Service(typeof(INotifySoundService))]
    internal class NotifySoundService : INotifySoundService, IDisposable
    {
        private readonly ServiceManager _serviceManager;
        private readonly AsyncOperation _uiAsyncOperation;

        /// <exception cref="ArgumentNullException"><paramref name="serviceProvider" /> is <c>null</c>.</exception>
        public NotifySoundService([NotNull] IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            _serviceManager = new ServiceManager(serviceProvider);

            IUIShell uiShell = _serviceManager.GetRequiredService<IUIShell>();
            _uiAsyncOperation = uiShell.CreateUIAsyncOperation();
        }

        #region INotifyIconService Members

        /// <summary>
        /// Проиграть звук - ответов не имеется
        /// </summary>
        public void PlayNoAnswers()
        {
            if (Config.Instance.SoundConfig.MakeSound)
            {
                Beeper.DoBeep(Config.Instance.SoundConfig.SoundFile3);
            }
        }

        /// <summary>
        /// Проиграть звук - имеются ответы в форумы.
        /// </summary>
        public void PlayAnswerPresent()
        {
            if (Config.Instance.SoundConfig.MakeSound)
            {
                Beeper.DoBeep(Config.Instance.SoundConfig.SoundFile1);
            }
        }

        /// <summary>
        /// Проиграть звук - имеются ответы мне в форумах.
        /// </summary>
        public void PlayAnswersMePresent()
        {
            if (Config.Instance.SoundConfig.MakeSound)
            {
                Beeper.DoBeep(Config.Instance.SoundConfig.SoundFile2);
            }
        }

        #endregion

        #region IDisposable Members

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            _uiAsyncOperation.OperationCompleted();
        }

        #endregion

        #region Private Members


        #endregion
    }
}